package observer;

/**
 * Created by simod on 2019/12/17
 */
class Observer1 extends Observer {
    private Subject subject;

    public Observer1(Subject subject) {
        this.subject = subject;
        subject.addObserver(this);
    }

    @Override
    public void update() {
        System.out.println("我是observer1:" + this.subject.getState());
    }
}

class Observer2 extends Observer {
    private Subject subject;

    public Observer2(Subject subject) {
        this.subject = subject;
        subject.addObserver(this);
    }

    @Override
    public void update() {
        System.out.println("我是observer2:" + this.subject.getState());
    }
}

class Observer3 extends Observer {
    private Subject subject;

    public Observer3(Subject subject) {
        this.subject = subject;
        subject.addObserver(this);
    }

    @Override
    public void update() {
        System.out.println("我是observer3:" + this.subject.getState());
    }
}

public class ObserverTest {
    public static void main(String[] args) {
        Subject subject = new Subject();
        new Observer1(subject);
        new Observer2(subject);
        new Observer3(subject);
        subject.setState("5");
    }
}
